using UnityEngine;
using System.Collections;

public class Projectile : MonoBehaviour 
{
	ConstantForce m_ConstantForce;
	
	float m_MaxMagnitude=30.0f;
	
	// Use this for initialization
	void Start () 
	{
		m_ConstantForce= this.transform.GetComponent<ConstantForce>();
	}
	
	// Update is called once per frame
	void Update () 
	{
		/*if(transform.rigidbody.velocity.magnitude>m_MaxMagnitude)
		{
			transform.rigidbody.velocity=transform.rigidbody.velocity.normalized*m_MaxMagnitude;	
		}*/
	}
	
	void OnTriggerEnter(Collider element)
	{
        if (Character.Instance.m_ModeProjectile == ProjectileBehavior.Explosion)
        {
            Vector3 m_ConstantForce = Vector3.zero;
            this.transform.rigidbody.velocity = Vector3.zero;

            Character.Instance.refExplosion = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/p_ProjectileExplosion"), transform.position, Quaternion.identity);

            GameObject[] g = GameObject.FindGameObjectsWithTag("Cube");
            for (int i = 0; i < g.Length; i++)
            {
                g[i].rigidbody.WakeUp();
            }

          //  GameObject.Find("Button").transform.rigidbody.WakeUp();
            GameObject.FindGameObjectWithTag("Char").rigidbody.WakeUp();
            Destroy(gameObject);
        }
	}

}
